package com.hwj.service.Impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hwj.entity.PetScience;
import com.hwj.mapper.PetScienceMapper;
import com.hwj.service.PetScienceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PetScienceServiceImpl implements PetScienceService {
    @Autowired
    PetScienceMapper petScienceMapper;


    @Override
    public PageInfo<PetScience> getByType(String type, Integer pageNum, Integer pageSize) {
        if(ObjectUtil.isEmpty(type)){
            return null;
        }
        PageHelper.startPage(pageNum,pageSize);
        return new PageInfo<>(petScienceMapper.getByType(type));
    }

    @Override
    public PetScience getById(Long id) {
        return petScienceMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<PetScience> getByTag(String tag) {
        tag="%"+tag+"%";
        return petScienceMapper.getByTag(tag);
    }

    @Override
    public PageInfo<PetScience> listByPage(String name, String type, Integer pageNum, Integer pageSize) {

        if(StrUtil.isNotEmpty(name)){
            name="%"+name+"%";
        }
        if(StrUtil.isNotEmpty(type)){
            type="%"+type+"%";
        }
        PageHelper.startPage(pageNum,pageSize);
        return new PageInfo<>(petScienceMapper.listByPage(name,type));
    }
}
